package cn.mxb.logic.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.mxb.floor.dao.impl.BaseDaoImpl;
import cn.mxb.floor.pagination.Result;
import cn.mxb.logic.entity.MxbCard;

@Repository("mxbCardDAO")
public class MxbCardDAO  extends BaseDaoImpl<MxbCard>   {

	/**
	 * 分页
	 * @return_type: Result<MxbCard>
	 */
	@SuppressWarnings("unchecked")
	public Result<MxbCard> find(MxbCard mxbCard, int page, int size){
		String queryString = "from MxbCard where 1=1";
		int start=(page-1)*size;
		int limit =size;
		String msg = "";
		return (Result<MxbCard>)super.find(queryString, null, null, start, limit,msg);
	}
	
	/**
	 * 根据字段property的值value查询
	 */
	@SuppressWarnings("unchecked")
	public List<MxbCard> findListByProperty(String property,String value){
		List<MxbCard> list = null;
		String queryString = "from MxbCard where "+property+" like '%"+value+"%'";
		
		try{
		   list = this.getHibernateTemplate().find(queryString);
		}catch(Exception e){
			System.out.println(e);
		}
		return list;
	}
	
	/**
	 * 
	 * 根据字段值查询(实体)
	 */
	@SuppressWarnings("unchecked")
	public MxbCard findByProperty(String property, String value) {
		List<MxbCard> list = null;
		MxbCard mxbCard = null;
		String queryString = "from MxbCard where "+property+" like '%"+value+"%'";
		try{
		   list = this.getHibernateTemplate().find(queryString);
		   if(list.size()>0 && list !=null){
			   mxbCard = list.get(0);
		   }else{
			   System.out.println("MxbCard kong");
		   }
		}catch(Exception e){
			System.out.println(e);
		}
		return mxbCard;
	}
	/**
	 * 修改table，根据property的value修改field为fieldvalue
	 */
	public void updatetablebyproperty(String table,String field,String property,String value,int fieldvalue) {
         System.out.println("update"+table);
	     String hql = " update "+table+" set "+field+" = ? where "+property+" = ? ";
	     Object values[] = {fieldvalue,value};
	     try{
	    	 update(hql, values);
	     }catch(Exception e){
	    	 System.out.println(e);
	     }
	}
}
